const { generateService } = require('@umijs/openapi')

generateService({
  schemaPath: "http://localhost:8080/v3/api-docs?group=zjb",
  serversPath: "./src/api/modules/dwh",
  templatesFolder: "./src/assets/openapi",
  namespace: "UserAPI",
  hook:{
    afterOpenApiDataInited:afterOpenApiDataInited,
    customFunctionName:customFunctionName
  }
});

function customFunctionName(data) {
  // return data.summary;
  // console.log(data.path.split("/"));
  // return data.operationId.split("_")[0]
  return data.path.split("/").pop();
}

// const tag = ['login-controller'];

function afterOpenApiDataInited(openAPIData) {
  // openAPIData.tags=openAPIData.tags.filter(item=>tag.includes(item.name));
  // let paths = openAPIData.paths;
  // Object.keys(paths).forEach(key => {
  //   let path = paths[key];
  //   Object.keys(path).forEach(method => {
  //     let operation = path[method];
  //     if (!tag.includes(operation.tags[0])) {
  //       delete paths[key]
  //     }
  //   })
  // })
  // openAPIData.components.schemas={}
  // openAPIData.paths=paths
  // console.log(JSON.stringify(openAPIData))
  return openAPIData;
}


